﻿#include <string>
#include <iostream>
using namespace std;

//请在此添加代码，实现书籍数据的输入、排序和输出
/********** Begin *********/
struct Book
{
	string shuming;
	float jiage;
};
int main()
{
	int n;
	Book book[100];
	cin  >> n;
	int k  = n;
	float temp  = 0;
	string temp1;
	int len  = 0, len1 = 0;
	for (int i  = 0; i  < n; i++)
	{
		getchar();//吸收掉上面cin>>n时输入的回车符号
		//如果要输入字符串 则需要在前面加getchar()
		getline(cin, book[i].shuming);//带空格的字符串输入
		cin  >> book[i].jiage;
	}
	for (int i  = 0; i  < n; i++)
	{
		k--;
		for (int j  = 0; j  < k; j++)
		{
			if (book[j].jiage  > book[j  + 1].jiage)
			{
				temp  = book[j].jiage;
				book[j].jiage  = book[j  + 1].jiage;
				book[j  + 1].jiage  = temp;
				temp1  = book[j].shuming;
				book[j].shuming  = book[j  + 1].shuming;
				book[j  + 1].shuming  = temp1;
			}
		}
	}
	for (int i1  = 0; i1  < n; i1++)
	{
		if (book[i1].jiage  == book[i1  + 1].jiage)
		{
			len  = book[i1].shuming.length();
			len1  = book[i1  + 1].shuming.length();
			if (len  > len1)
			{
				temp  = book[i1].jiage;
				book[i1].jiage  = book[i1  + 1].jiage;
				book[i1  + 1].jiage  = temp;
				temp1  = book[i1].shuming;
				book[i1].shuming  = book[i1  + 1].shuming;
				book[i1  + 1].shuming  = temp1;
			}
		}
	}
	for (int i2  = 0; i2  < n; i2++)
	{
		cout  << book[i2].jiage  << ", " << book[i2].shuming  << endl;
	}
	return 0;
}
/********** End **********/
